#ifndef IMAGE_TEXTURE_H
#define IMAGE_TEXTURE_H
#include<texture.h>
#include<QImage>
#include<QDebug>
class image_texture:public texture
{
public:
    image_texture(){};
    image_texture(QImage*image){
        this->image=image;
    }
    virtual QVector3D value(float u,float v,const QVector3D&p)const
    {
//        qDebug()<<image->width()<<","<<image->height()<<"\n";
        int i=u*image->width();
        int j=v*image->height();

        if(i<0)i=0;
        if(j<0)j=0;
        if(i>image->width()-1)i=image->width()-1;
        if(j>image->width()-1)j=image->width()-1;

//        int*r,*g,*b;
        QColor color= image->pixelColor(i,j);
//        qDebug()<<*r<<","<<*g<<"\n";
//        QVector3D color(*r/255.0,*g/255.0,*b/255.0);
//        qDebug()<<;
        QVector3D vcolor(color.red()/255.0,color.green()/255.0,color.blue()/255.0);
        return vcolor;

    }
private:
    QImage*image;
};

#endif // IMAGE_TEXTURE_H
